<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="layuiadmin/plugins/dtree/dtree/dtree.css">
<link rel="stylesheet" href="layuiadmin/plugins/dtree/dtree/font/dtreefont.css">
  <style type="text/css">
	.layui-form .layui-form-item{
		width:90%;
	}
	</style>
</head>
<body style="margin-top: 10px">
<form class="layui-form" lay-filter="myform">
<input type="hidden" name="id">
<input type="hidden" name="state" value="1">
<input type="hidden" name="orgId" id="orgId" th:value="${session.MEORG.id}">
		<div class="layui-form-item">
			 <div class="layui-inline">
                <label class="layui-form-label">选择试卷</label>
                <div class="layui-input-inline">
                <input type="text" name="paperName" id="paperName"  autocomplete="off" class="layui-input" select>
                <input type="hidden" name="paperId" id="paperId">
            </div>
            </div>
		    <label class="layui-form-label">部门</label>
		    <div class="layui-input-inline">
      			<ul id="nodeOrgId" name="nodeOrgId" class="dtree" data-id="0" ></ul>
    		</div>
	  	</div>
		<button id="submitBtn" class="layui-btn" style="display:none" lay-submit lay-filter="submitme">保存</button>
</form>
<script src="layuiadmin/plugins/xm-select/xm-select.js"></script>
 <script type="text/javascript" th:inline="javascript">
/*<![CDATA[*/
var id=/*[[${id}]]*/ 
var orgId=/*[[${orgId}]]*/ 
var myorgId=/*[[${session.MEORG.id}]]*/

/*]]>*/
</script>
<script th:inline="none">
layui.extend({ 
	dtree: '{/}layuiadmin/plugins/dtree/dtree/dtree'
});
layui.use(['element','table','dtree','form','upload','laydate'], function(){
    var form = layui.form,
    element = layui.element,
    laydate = layui.laydate,
    upload = layui.upload,
    dtree = layui.dtree;
    $("#paperName").on("click",function(){
  	    top.layer.open({
            id:"openwin",
            type: 2,
            title:'选择试卷',
            area:['1300px','750px'],
            content:  'rooter?url=ksxt/stat/paper-select',
            btn:['选择','关闭'],
            yes:function(index,layero){
            	var iframeWin = top[layero.find('iframe')[0]['name']];
            	let r = iframeWin.getId();
            	$("#paperId").val(r.id);
            	$("#paperName").val(r.name);
            	top.layer.close(index);
            }
        });
  	})
    var orgTree = dtree.renderSelect({
		  elem: "#nodeOrgId",
		  url: "org/getDTree",
		  checkbar: false ,
		  selectTips: "选择部门",
		  done:function(a,b,c){
		  }
	});
	form.on('submit(submitme)', function(data){
		var values = {};
		$(":input").each(function(i,v){
			if(v.name)
			values[v.name] = v.value;
		})
		values.nodeOrgId = values.nodeOrgId_select_nodeId;
		var url = 'user/save';
		$.ajax({
			url: url,
			data: JSON.stringify(values),
			type:'POST',
			dataType:'JSON',
			contentType:"application/json",
			success: function(res){
				if(res.code!=0){
					layer.msg(res.msg);
				}else{
					let win = getTabWin();
					win.loadGrid("user-table");
					layer.msg("保存成功");
					var index = top.layer.getFrameIndex(window.name); 
					top.layer.close(index); 
				}
			}
		})
		return false; 
	});
});
</script>
</body>
</html>